/* Copyright (c) 2004-2024 Peigen.info. All rights reserved. */

package info.peigen.hotpot.component.gateway.socket.queue;

import cn.hutool.core.util.ObjectUtil;
import lombok.extern.slf4j.Slf4j;
import org.noear.solon.annotation.Component;
import org.smartboot.socket.transport.AioSession;

import java.util.concurrent.LinkedBlockingQueue;

/**
 * <b>(SocketSessionQueue)</b>
 * 电桩session管理
 *
 * @author czj
 * @version 1.0.0
 * @since 2022/11/17
 */
@Slf4j
@Component("socketSessionQueue")
public class SocketSessionQueue {
    private LinkedBlockingQueue<AioSession> sessions = new LinkedBlockingQueue();

    public AioSession getSession(String sessionId) {
        for (AioSession session : sessions) {
            if (ObjectUtil.equals(sessionId, session.getSessionID())) {
                return session;
            }
        }
        return null;
    }

    public void add(AioSession session) {
        sessions.add(session);
    }

    public void remove(AioSession session) {
        sessions.remove(session);
    }
}
